package com.jinlejia.feedback.question.adapter.question;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.jinlejia.feedback.databinding.FbAdapterQuestionDetailsProgressBinding;

import java.util.ArrayList;
import java.util.Map;

/**
 * 最新进度 标题
 */

public class LatestProgressTitleHolderHelper {

    public static void bindViewHolder(KeyHelper.EventListener eventListener,final RecyclerView.Adapter adapter, ViewHolder holder, final ArrayList<Map<String, Object>> mData, int position){
        final FbAdapterQuestionDetailsProgressBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.titleLayout.setVisibility(View.VISIBLE);

        Map<String, Object> map = mData.get(position);
        if (Boolean.parseBoolean(String.valueOf(map.get(KeyHelper.LocalIsShowAll)))){
            binding.simpleLayout.setVisibility(View.GONE);
            binding.showAllInfoTextView.setVisibility(View.GONE);
            binding.bottomEmptyView.setVisibility(View.GONE);
        }else {
            binding.simpleLayout.setVisibility(View.VISIBLE);
            binding.showAllInfoTextView.setVisibility(View.VISIBLE);
            binding.bottomEmptyView.setVisibility(View.VISIBLE);
        }
        binding.setMap(map);
        binding.infoLayout.setVisibility(View.GONE);
        binding.showAllInfoTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.showAllInfoTextView.setVisibility(View.GONE);
                binding.simpleLayout.setVisibility(View.GONE);
                for (int i = 0; i < mData.size(); i++) {
                    Map<String,Object> map = mData.get(i);
                    if ("4".equals(String.valueOf(map.get("type"))) || "3".equals(String.valueOf(map.get("type")))){
                        map.put(KeyHelper.LocalIsShowAll,true);
                        adapter.notifyItemChanged(i);
                    }
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public ViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }
}
